<?php

namespace IDock\Insurance\LIHI\Request;

use IDock\Insurance\LIHI\LIHIEnums;
use IDock\Insurance\LIHI\Response\VehicleActualValueResponse;
use IDock\Visitor\VehicleActualValueVisitor;

class VehicleActualValueRequest extends AllLIHIRequest
{
    public $route = 'query/coverageCalculation';

    protected $response = VehicleActualValueResponse::class;

    protected $urlTip = '车辆实际价值';

    /*** @var  VehicleActualValueVisitor $visitor */
    protected $visitor;

    public function generate(): array
    {
        $arr = [
            'riskCode' => '0502',
            'carKind' => LIHIEnums::$carKindCode[$this->visitor->carKindCode] ?? '',
            'seatCount' => $this->visitor->vehicleSeat,
            'useNatureCode' => PremiumInquiryRequest::getUseNatureCode(
                $this->visitor->useNatureCode,
                $this->visitor->causeType,
                $this->visitor->carKindCode
            ),

            'purchasePrice' => $this->visitor->vehiclePrice,
            'enrollDate' => date('Y-m-d', strtotime($this->visitor->firstRegisterDate)),
            'prpStartDate' => date('Y-m-d', strtotime($this->visitor->startDate)),
            'fuelType' => array_reverse(LIHIEnums::$energyType)[$this->visitor->energyType] ?? '',
            'newEnergyFlag' => $this->visitor->isNewEnergy,
        ];
        if (empty($arr['carKind'])) {
            throw new \Exception("不支持该车辆类型");
        }
        if (empty($arr['useNatureCode'])) {
            throw new \Exception("不支持该车辆用途");
        }
        return $arr;
    }

}
